import time
from unittest import TestCase
from selenium import webdriver
from selenium.webdriver.common.by import By

class TestLoan(TestCase):
    def testLoan1(self):
        username='lisi'
        password='123456'
        expext='14条'
        driver=webdriver.Chrome()
        driver.get("http://localhost:90")
        driver.maximize_window()
        driver.find_element(By.ID, 'username').send_keys(username)
        driver.find_element(By.ID, 'password').send_keys(password)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys('10000')
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys('10')
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[4]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[4]/ul/li[2]/a').click()
        result=driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div[2]/div[2]/div/button[6]/span').text
        if result!=expext:
            driver.save_screenshot('10条')
        self.assertEqual(expext,result)
        driver.close()
    def testLoan2(self):
        username = 'lisi'
        password = '123456'
        admin='admin'
        new_password='123456'
        expect='账户余额：20000.00元'
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        driver.maximize_window()
        driver.find_element(By.ID, 'username').send_keys(username)
        driver.find_element(By.ID, 'password').send_keys(password)
        driver.find_element(By.XPATH,'//*[@id="login_btn"]').click()
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys('10000')
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys('10')
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(2)
        # driver.close()
        driver.find_element(By.XPATH,'/html/body/div/div/header/nav/div/ul/li[1]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/header/nav/div/ul/li[1]/ul/li[4]/a').click()
        driver.find_element(By.ID, 'username').send_keys(admin)
        driver.find_element(By.ID, 'password').send_keys(new_password)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[5]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[5]/ul/li[1]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[7]/button[1]').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/header/nav/div/ul/li[1]/a/img').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/header/nav/div/ul/li[1]/ul/li/a').click()
        time.sleep(2)
        driver.find_element(By.ID, 'username').send_keys(username)
        driver.find_element(By.ID, 'password').send_keys(password)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[4]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        time.sleep(2)
        result=driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div[3]/div/div/div[2]/h4[2]').text
        if result!=expect:
            driver.save_screenshot('11111.png')
        self.assertEqual(expect,result)
        driver.close()

    def testLoan3(self):
        username = 'lisi5'
        password = '123456'
        expext = '申请失败，请先绑定个人信息'
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        driver.maximize_window()
        driver.find_element(By.ID, 'username').send_keys(username)
        driver.find_element(By.ID, 'password').send_keys(password)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys('10000')
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys('10')
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(2)
        result = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        if result != expext:
            driver.save_screenshot('10条')
        self.assertEqual(expext, result)
        driver.close()
    def testLoan4(self):
        username = 'lisi'
        password = '123456'
        expext = '申请失败'
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        driver.maximize_window()
        driver.find_element(By.ID, 'username').send_keys(username)
        driver.find_element(By.ID, 'password').send_keys(password)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys(
            '10000000000')
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(
            '10')
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(2)
        result = driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        if result != expext:
         driver.save_screenshot('10条')
        self.assertEqual(expext, result)
        driver.close()

    def testLoan5(self):
        username = 'lisi'
        password = '123456'
        expext = '24条'
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        driver.maximize_window()
        driver.find_element(By.ID, 'username').send_keys(username)
        driver.find_element(By.ID, 'password').send_keys(password)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys(
            '10')
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(
            '10')
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[4]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[4]/ul/li[2]/a').click()
        result = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div[2]/div[2]/div/button[6]/span').text
        if result != expext:
            driver.save_screenshot('25条.png')
        self.assertEqual(expext,result)
        driver.close()
    def testLoan6(self):
        username = 'lisi'
        password = '123456'
        expext = '输入期限不合法！'
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        driver.maximize_window()
        driver.find_element(By.ID, 'username').send_keys(username)
        driver.find_element(By.ID, 'password').send_keys(password)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys(
            '10')
        time.sleep(2)
        driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(
            '100000000')
        time.sleep(2)
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
        time.sleep(2)
        result = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/span').text
        if result != expext:
            driver.save_screenshot('期限不合法.png')
        self.assertEqual(expext, result)
        driver.close()

    def testLoan7(self):
            username = 'lisi'
            password = '123456'
            expext = '27条'
            driver = webdriver.Chrome()
            driver.get("http://localhost:90")
            driver.maximize_window()
            driver.find_element(By.ID, 'username').send_keys(username)
            driver.find_element(By.ID, 'password').send_keys(password)
            driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
            driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/a').click()
            time.sleep(2)
            driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
            time.sleep(2)
            driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys(
                '10')
            time.sleep(2)
            driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(
                '9999')
            time.sleep(2)
            driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button').click()
            time.sleep(2)
            driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
            time.sleep(2)
            driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[4]/a').click()
            time.sleep(2)
            driver.find_element(By.XPATH,'/html/body/div/div/aside/div[2]/nav/ul/li[4]/ul/li[2]/a').click()
            result = driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div[2]/div[2]/div/button[6]/span').text
            if result != expext:
                driver.save_screenshot('26条.png')
            self.assertEqual(expext, result)
            driver.close()
